import { getDeviceGroupTreeNodeExclude } from '@/api/iot/admin/device';
import { AdColumn } from '@/components/AdVxeTable';
import { useI18n } from '@/hooks/web/useI18n';

const { t } = useI18n();

export const columns: AdColumn[] = [
  {
    title: t('entity.idTitle'),
    field: 'Id',
    width: 180,
    visible: false,
    formVisible: true,
    formEditable: false,
    filterable: true,
    dataType: 'integer',
  },
  {
    title: t('iot.route.device.group.nameText'),
    field: 'Name',
    width: 200,
    treeNode: true,
    formVisible: true,
    required: true,
    filterable: true,
    dataType: 'string',
  },
  {
    title: t('iot.route.device.group.descriptionText'),
    field: 'Description',
    width: 200,
    formVisible: true,
    filterable: true,
    dataType: 'string',
  },
  {
    title: t('iot.route.device.group.remarkText'),
    field: 'Remark',
    width: 200,
    formVisible: true,
    filterable: true,
    dataType: 'text',
  },
  {
    title: t('iot.route.device.group.orderNumberText'),
    field: 'OrderNumber',
    width: 80,
    filterable: false,
    dataType: 'number',
  },
  {
    title: t('iot.route.device.group.treePathStringText'),
    field: 'TreePathString',
    width: 0,
    visible: false,
    formVisible: false,
    formEditable: false,
    filterable: false,
    dataType: 'text',
  },
  {
    title: t('iot.route.device.group.parentIdText'),
    field: 'ParentId',
    width: 0,
    visible: false,
    formVisible: true,
    formEditable: true,
    filterable: true,
    dataType: 'integer',
    formRender: {
      name: 'ApiTreeSelect',
      props: {
        api: getDeviceGroupTreeNodeExclude,
        // params: formModel.Id,
        labelField: 'Name',
        valueField: 'Id',
        childrenField: 'Items',
        allowClear: true,
        showSearch: true,
        treeNodeFilterProp: 'Name',
        treeDefaultExpandAll: true,
        // not request untill to select
        immediate: true,
      },
    },
  },
  {
    title: t('iot.route.device.group.levelText'),
    field: 'Level',
    width: 50,
    formVisible: true,
    formEditable: false,
    filterable: false,
    dataType: 'integer',
  },
  {
    title: t('entity.creationAudited.creatorIdTitle'),
    field: 'CreatorId',
    width: 0,
    visible: false,
    formVisible: true,
    formEditable: false,
    filterable: true,
    dataType: 'string',
  },
  {
    title: t('entity.creationAudited.creatorNameTitle'),
    field: 'CreatorName',
    width: 100,
    formVisible: true,
    formEditable: false,
    filterable: true,
    filterIndex: 'CreatorId',
    filterJoin: {
      entityType: 'EaCloud.Pack.Identity.Entities.User,EaCloud.Pack.Identity',
      filterField: 'UserName',
      selectField: 'Id',
    },
    dataType: 'string',
  },
  {
    title: t('entity.creationAudited.creatorNicknameTitle'),
    field: 'CreatorNickname',
    width: 100,
    formVisible: true,
    formEditable: false,
    filterable: true,
    filterIndex: 'CreatorId',
    filterJoin: {
      entityType: 'EaCloud.Pack.Identity.Entities.User,EaCloud.Pack.Identity',
      filterField: 'NickName',
      selectField: 'Id',
    },
    dataType: 'string',
  },
  {
    title: t('entity.creationAudited.createdTimeTitle'),
    field: 'CreatedTime',
    width: 180,
    formVisible: true,
    formEditable: false,
    filterable: true,
    dataType: 'datetime',
  },
  {
    title: t('entity.updateAudited.updaterIdTitle'),
    field: 'UpdaterId',
    width: 0,
    visible: false,
    formVisible: true,
    formEditable: false,
    filterable: true,
    dataType: 'string',
  },
  {
    title: t('entity.updateAudited.updaterNameTitle'),
    field: 'UpdaterName',
    width: 100,
    formVisible: true,
    formEditable: false,
    filterable: true,
    filterIndex: 'UpdaterId',
    filterJoin: {
      entityType: 'EaCloud.Pack.Identity.Entities.User,EaCloud.Pack.Identity',
      filterField: 'UserName',
      selectField: 'Id',
    },
    dataType: 'string',
  },
  {
    title: t('entity.updateAudited.updaterNicknameTitle'),
    field: 'UpdaterNickname',
    width: 100,
    formVisible: true,
    formEditable: false,
    filterable: true,
    filterIndex: 'UpdaterId',
    filterJoin: {
      entityType: 'EaCloud.Pack.Identity.Entities.User,EaCloud.Pack.Identity',
      filterField: 'NickName',
      selectField: 'Id',
    },
    dataType: 'string',
  },
  {
    title: t('entity.updateAudited.updatedTimeTitle'),
    field: 'UpdatedTime',
    width: 180,
    formVisible: true,
    formEditable: false,
    filterable: true,
    dataType: 'datetime',
  },
];
